package com.yanqu.road.server.cmd.activity.springunionbanquet;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SpringUnionBanquetProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.activity.springunionbanquet.CrossSpringUnionBanquetActivity;
import com.yanqu.road.server.manager.activity.springunionbanquet.CrossSpringUnionBanquetActivityMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.Protocol;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = Protocol.C_SPRING_UNION_BANQUET_OPEN, desc = "宴请")
public class CrossSpringUnionBanquetOpenCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        SpringUnionBanquetProto.CrossSpringUnionBanquetOpenReqMsg reqMsg = SpringUnionBanquetProto.CrossSpringUnionBanquetOpenReqMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        String unionUid = reqMsg.getUnionUid();
        UserBaseInfo userBaseInfo = PlayerBasePb.parseToUserBaseInfo(reqMsg.getUserBaseInfo());
        CrossUserMgr.updateUserBaseInfo(packet.getPlayerId(), userBaseInfo);
        CrossSpringUnionBanquetActivity activity = CrossSpringUnionBanquetActivityMgr.getActivity(activityId);
        if(activity != null){
            List<Long> memberList = new ArrayList<>(reqMsg.getMemberList());
            activity.openBanquet(packet.getPlayerId(), userBaseInfo, unionUid, reqMsg.getGoodsId(), reqMsg.getMaxMemberCount(), memberList);
        }

    }

    @Override
    public void sendData() {

    }
}
